package com.yifeng.repo.base.security.auth.impl;

import com.gomcarter.frameworks.base.common.AssertUtils;
import com.yifeng.repo.base.dto.PermissionDto;
import com.yifeng.repo.base.dto.UserDto;
import com.yifeng.repo.base.params.ConsoleParam;
import com.yifeng.repo.base.security.auth.constant.SecurityTypeEnum;
import com.yifeng.repo.base.security.console.PermissionRestService;
import com.yifeng.repo.base.security.console.impl.CustomerPermissionServiceImpl;
import com.yifeng.repo.base.security.context.params.SecurityCheckParam;
import com.yifeng.repo.base.utils.action.BizCacheAction;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * Created by daibing on 2024/2/28.
 */
@Slf4j
public class CustomerSecurityChecker extends AbstractSecurityChecker {

    private SecurityCheckParam checkParam;
    private PermissionRestService securityService;

    @Override
    public SecurityTypeEnum securityType() {
        return SecurityTypeEnum.CUSTOMER;
    }

    @Override
    public void init(SecurityCheckParam checkParam, ConsoleParam consoleParam, BizCacheAction bizCacheAction) {
        this.checkParam = checkParam;
        this.securityService = new CustomerPermissionServiceImpl(consoleParam);
    }

    @Override
    protected List<String> listPublicKey() {
        AssertUtils.notNull(securityService, "未初始化2C鉴权服务！");
        return securityService.listPublicKey();
    }

    @Override
    protected boolean onlyGetTokenFromHeader() {
        if (checkParam == null) {
            return true;
        } else {
            return checkParam.isOnlyGetTokenFromHeader();
        }
    }

    @Override
    public PermissionDto checkAndGetPermission(UserDto userDto) {
        throw new UnsupportedOperationException("会员不支持该操作！");
    }

    @Override
    public boolean checkApiSecured(UserDto userDto, String resource) {
        throw new UnsupportedOperationException("会员不支持该操作！");
    }

    @Override
    public boolean checkStoreSecured(UserDto userDto, List<String> storeCodeList) {
        throw new UnsupportedOperationException("会员不支持该操作！");
    }
}
